<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>AWS Lambda Request</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            text-align: center;
            background-color: #f7f7f7;
        }
        h1 {
            margin-top: 40px;
        }
        .container {
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
        }
        .form {
            width: 400px;
            padding: 20px;
            border: 1px solid #ddd;
            border-radius: 5px;
            background-color: #fff;
            box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
        }
        .form label {
            display: block;
            margin-bottom: 10px;
        }
        .form input[type="text"],
        .form select {
            width: 100%;
            padding: 10px;
            margin-bottom: 20px;
            border: 1px solid #ddd;
            border-radius: 3px;
        }
        .form button {
            width: 100%;
            padding: 10px;
            background-color: #4CAF50;
            color: white;
            border: none;
            border-radius: 3px;
            cursor: pointer;
        }
        .popup {
            position: fixed;
            top: 50%;
            left: 50%;
            transform: translate(-50%, -50%);
            padding: 20px;
            background-color: #4CAF50;
            color: white;
            border-radius: 5px;
            box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
            z-index: 9999;
        }
    </style>
</head>
<body>
    <div class="container">
        <div class="form">
            <h1>亚马逊云AWS重启</h1>
            <label for="instanceID">服务器实例ID:</label>
            <input type="text" id="instanceID" th:value="${dto.serverInstanceId}" readonly="readonly">
            <label for="action">Ip:</label>
            <input type="text" th:value="${dto.serverIp}" readonly="readonly">
            <button onclick="sendRequest()">重新启动</button>
        </div>
    </div>

    <div id="popup" class="popup" style="display: none;">
        	请求成功!!!
    </div>

    <script>
        function sendRequest() {
            var instanceID = document.getElementById('instanceID').value;

            var url = '[[${dto.url}]]';

            var data = {
                instanceID: instanceID,
                action: '3'
            };

            fetch(url, {
                method: 'POST',
                headers: {
                    'Content-Type': 'application/json'
                },
                body: JSON.stringify(data)
            })
            .then(response => response.json())
            .then(result => {
                console.log(result);
                // Process the response as needed

                // Show popup notification
                showPopup();
            })
            .catch(error => {
                console.error(error);
                // Handle error
            });
        }

        function showPopup() {
            var popup = document.getElementById('popup');
            popup.style.display = 'block';

            setTimeout(function() {
                popup.style.display = 'none';
            }, 5000);
        }
    </script>
</body>
</html>